#pragma once
#include "Input.h"
#include "Output.h"
#include "Motor.h"

#include <vector>
using namespace std;

class  CDeviceManager
{
public:
	 CDeviceManager();
	 ~CDeviceManager(void);
public:
	class CInputManager
	{
	public:
		CInputManager();
		~CInputManager();
		CInput * operator[] (int nID);
		int GetNumInputs(){ return m_nInputs;}

	private:
		friend CDeviceManager;
		int		m_nInputs;
		vector<CInput*> m_ppInputs;
	};
	class COutputManager
	{
	public:
		COutputManager();
		~COutputManager();
		COutput * operator[] (int nID);
		int GetNumOutputs(){ return m_nOutputs;}

	public:
		 void SaveAllOutputStates(void);
		 BOOL IsAnyOutputStateChanged(void);

	private:
		friend CDeviceManager;
		int		m_nOutputs;
		vector<COutput*> m_ppOutputs;
	};
	class CMotorManager
	{
	public:
		CMotorManager();
		~CMotorManager();
		CMotor * operator[] (int nID);
		int GetNumMotors() { return m_nMotors; }

	public:
		 void SetAllSvonOff();
		 void SaveAllMotorLocs(void);
		 void StopAllMotors();
		 void BreakAllMotion(BOOL bActive = TRUE);
		 BOOL IsAnyMotorLocChanged(void);
		
	private:
		 friend CDeviceManager;
		 int		m_nMotors;
		 vector<CMotor*> m_ppMotors;
	};
public:
	static CDeviceManager * GetInstance();
	CInputManager & GetInputManger(){return m_Input;}
	COutputManager & GetOutputManager(){return m_Output;}
	CMotorManager & GetMotorManager(){return m_Motor;}

public:
     CString m_strError;
	 CInputManager m_Input;
	 COutputManager m_Output;
	 CMotorManager m_Motor;

public:
	static void Destroy();
	BOOL Initialize(int nInputs, int nOutputs,int nMotors);

private:
	static	CDeviceManager *m_pInstance;
};

#define		INPUTS		((*CDeviceManager::GetInstance())GetInputManger())
#define		OUTPUTS		((*CDeviceManager::GetInstance())GetOutputManager())
#define		MOTORS		((*CDeviceManager::GetInstance())GetMotorManager())


/*
	I_AlmStatus
	I_ChangeCurSpeed
	I_CloseDevice
	I_GetCmdPos
	I_GetCurSpeed
	I_GetInputState
	I_GetOutputState
	I_GetPos
	I_InpStatus
	I_MotionStatus
	I_MoveStop
	I_NelStatus
	I_OpenDevice
	I_OrgStatus
	I_PelStatus
	I_RdyStatus
	I_SMoveAbs
	I_SMoveRel
	I_SetAlmLogic
	I_SetBackLash
	I_SetCmdPos
	I_SetEncorderSource
	I_SetEndLimitLogic
	I_SetInpLogic
	I_SetOrgLogic
	I_SetOutputState
	I_SetPos
	I_SetPulseInputMode
	I_SetPulseOutputMode
	I_SetRdyLogic
	I_SetServoOn
	I_SetSvonLogic
	I_StartHome
	I_SvonStatus
	I_TContinueMove
	I_TMoveAbs
	I_TMoveRel
*/